import { request } from '@/utils/request'

enum API {
  MEMBER_LEVEL_LIST_URL = '/api/member/memberlevel/list',
  MEMBER_LEVEL_DELETE_URL = '/api/member/memberlevel/delete',
  MEMBER_LEVEL_INFO_URL = '/api/member/memberlevel/info',
  MEMBER_LEVEL_UPDATE_COMMIT = '/api/member/memberlevel',
}

export const reqMemberLevelList = (page: number, limit: number, key: string) =>
  request.get<any, any>(
    API.MEMBER_LEVEL_LIST_URL + `?page=${page}&limit=${limit}&key=${key}`,
  )

export const reqMemberLeveDelete = (id: any) =>
  request.get<any, any>(API.MEMBER_LEVEL_DELETE_URL + `/${id}`)

export const reqMemberLeveInfo = (id: number) =>
  request.get<any, any>(API.MEMBER_LEVEL_INFO_URL + `/${id}`)

// UPDATE提交
export const reqMemberLeveUpdateCommit = (
  type: string,
  id: number,
  name: string,
  growthPoint: number,
  defaultStatus: number,
  freeFreightPoint: number,
  commentGrowthPoint: number,
  priviledgeFreeFreight: number,
  priviledgeMemberPrice: number,
  priviledgeBirthday: number,
  note: string,
) => {
  if (type == 'save') {
    return request.post<any, any>(API.MEMBER_LEVEL_UPDATE_COMMIT + `/${type}`, {
      name,
      growthPoint,
      defaultStatus,
      freeFreightPoint,
      commentGrowthPoint,
      priviledgeFreeFreight,
      priviledgeMemberPrice,
      priviledgeBirthday,
      note,
    })
  } else {
    return request.post<any, any>(API.MEMBER_LEVEL_UPDATE_COMMIT + `/${type}`, {
      id,
      name,
      growthPoint,
      defaultStatus,
      freeFreightPoint,
      commentGrowthPoint,
      priviledgeFreeFreight,
      priviledgeMemberPrice,
      priviledgeBirthday,
      note,
    })
  }
}
